<meta name="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
$(function(){
	//导入会员数据
	$("#btn_import").click(function(){
		return;
		var oldUrl = $("form[name=taskForm]").attr("action");
		var importUrl = "yueyogaAdmin/importMember.jhtml";
		$("form[name=taskForm]").attr("action", importUrl);
		$("form[name=taskForm]").submit();
		$("form[name=taskForm]").attr("action", oldUrl);
	});
	//--导出数据
	$("#btn_export").click(function(){
		var oldUrl = $("form[name=taskForm]").attr("action");
		var exporttUrl = "yueyogaAdmin/exportMember.jhtml";
		$("form[name=taskForm]").attr("action", exporttUrl);
		$("form[name=taskForm]").submit();
		$("form[name=taskForm]").attr("action", oldUrl);
	});
});

</script>
<!--#if(totalspeakers== null || totalspeakers==0)-->
<div class="panel-body">
	<p>没有符合条件的数据</p>
</div>
<!--#else-->
<!--#var(Member member, PaginatedList<Member> members)-->
<div class="panel-heading panel-result-title">
	<h3 class="panel-title">查询结果</h3>
	<div class="btn-group btn-group-sm btn-gp-default">
		<button id="btn_edit" type="button" class="btn btn-default panel-radius-left" onclick="window.location.href='yueyogaAdmin/toAddMember.jhtml'">添加</button>
		<button id="btn_edit" type="button" class="btn btn-default panel-radius-none" onclick="updateMember()">修改</button>
		<button id="btn_delete" type="button" class="btn btn-default panel-radius-none" onclick="deleteMember()">删除</button>
		<button id="btn_import" type="button" onclick="slideImpDIV()" class="btn btn-default panel-radius-none">导入</button>
		<button id="btn_export" type="button" class="btn btn-default panel-radius-right">导出</button>
	</div>
</div>
<table id="tb_members" class="table table-bordered table-hover table-condensed" style="text-align: center; width:100%;">
	<tr class="tr-edit">
		<td width="40px"><input type="checkbox" onclick="selectAll()" name="controlAll" id="controlAll"></td>
		<td width="90px">编号</td>
		<td width="90px">姓名</td>
		<td width="100px">手机号</td>
		<td width="130px">信息来源</td>
		<td width="120px">会籍顾问</td>
		<td width="120px">负责人</td>
		<td width="140px">卡项</td>
		<td width="140px">最后到馆</td>
		<td width="140px">有效期</td>
	</tr>
	<!--#foreach(member in members)-->
	<tr>
		<td class="table-edit"><input type="checkbox" name="selected" value="${member.memberid}"></td>
		<td class="table-edit"><a href="yueyogaAdmin/toMemberDetail.jhtml?id=${member.memberid}">${member.cardnumber}</a></td>
		<td class="table-edit"><a href="yueyogaAdmin/toMemberDetail.jhtml?id=${member.memberid}">${member.name}</a></td>
		<td class="table-edit"><a href="yueyogaAdmin/toMemberDetail.jhtml?id=${member.memberid}">${member.phone}</a></td>
		<td class="table-edit">
			<!-- #if(member.marketingsource=='81') --> 电话打入 <!-- #else(member.marketingsource=='82') --> 主动拜访 <!-- #else(member.marketingsource=='83') --> 数据库 <!-- #else(member.marketingsource=='84') --> 线上活动 <!-- #else(member.marketingsource=='85') --> 线下活动 <!-- #else(member.marketingsource=='86') --> 其他 <!-- #else-->
			&nbsp; <!-- #end -->
		</td>
		<td class="table-edit">${member.keeperName}</td>
		<td class="table-edit">${member.fuzerenName}</td>
		<td class="table-edit">${member.productName}</td>
		<td class="table-edit">${member.lastConsumeTime}</td>
		<!-- #if(member.productExpired) -->  
		<td class="table-edit" style="background-color:#FF6A6A;">${member.stringOfProductEndTime}</td>
		<!-- #else --> 
		<td class="table-edit">${member.stringOfProductEndTime}</td>
		<!-- #end -->
	<tr>
		<!--#end-->
</table>
<!--
#set(
pager = members.pager,
totalResults = pager.getCountOfTotalResults(),
totalPages = pager.getCountOfTotalPages() * 1,
pageSize = pager.pageSize,
pageNo = pager.pageNo,
prePageNo = pager.getPrevPageNo(),
nextPageNo = pager.getNextPageNo()
)
-->
<!-- 列表分页 -->
<div class="paging-page">$!{include("paging_page.html")}</div>
<!--#end-->

<!-- 用于导入数据的div -->
<div id="div_import" class="panel-dialog-import" style="display:none;">
	<div class="panel-heading panel-result-title">
			<h3 class="panel-title">导入会员数据</h3>
		</div>
		<div style="margin: 0 30px;" class="clear">
			<form role="form" id="uploadFile" name="uploadFile" action="yueyogaAdmin/toUploadFile.jhtml" method="post" enctype="multipart/form-data">
			<div>
			<label class="col-sm-1 control-label label-pro-chose">模板:</label>
			<label class="col-sm-1 control-label label-pro-chose" style="width:150px !important;"><a href="yueyogaAdmin/downloadTemplate.jhtml" id="a_import_mb">${mbName}</a></label>
			</div>
			<br>
			<div>
			<input id="lefile" name="xlsfile" type="file" style="display:none;" onChange="uploadXlsx()">
			<button type="button" onclick="$('input[id=lefile]').click();" class="btn btn-success btn-sm" style="margin:5px;width:234px;">请选择会员Excel</button> 
			<input type="hidden" id="basePath" value="${basePath}"/>
			<input type="hidden" id="filePath" name="filePath"/>
			<label class="col-sm-1 control-label label-pro-chose">模板导入:</label>
			</div>
			<div class="panel-btn-search" style="text-align: right; margin: 20px;">
				<button id="btnImp" type="button" onclick="importMembers()" class="btn-adet-default">导入会员</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_close" onclick="slideImpDIV()" class="btn-adet-default">取消</button>
			</div>
			</form>
		</div>
</div>

<script>
	
	function selectAll() {
		var checklist = document.getElementsByName("selected");
		if (document.getElementById("controlAll").checked) {
			for (var i = 0; i < checklist.length; i++) {
				checklist[i].checked = 1;
			}
		} else {
			for (var j = 0; j < checklist.length; j++) {
				checklist[j].checked = 0;
			}
		}
	}
	function deleteMember() {
		var checklist = document.getElementsByName("selected");
		var ids = "";
		for (var i = 0; i < checklist.length; i++) {
			if (checklist[i].checked) {
				ids = ids + checklist[i].value + ",";
			}
		}
		if (ids == "") {
			alert("请选择要删除的行");
		} else {
			confirm(
					"确定要删除吗",
					function() {
						this.close();
						ids = ids.substring(0, ids.length - 1);
						var d = wait("正在删除，请稍候...");
						var url = "yueyogaAdmin/deleteMember.jhtml?ids=" + ids;
						$
								.post(
										url,
										function(response) {
											if (response) {
												d.content("删除成功");
												setTimeout(function() {
													d.close().remove();
												}, 300);
												window.location.href = "yueyogaAdmin/searchMember.jhtml";
											} else {
												alert("删除失败!");
											}
										}, "json");
					});
		}
	}
	function updateMember() {
		var checklist = document.getElementsByName("selected");
		var id = "";
		var count = 0;
		for (var i = 0; i < checklist.length; i++) {
			if (checklist[i].checked) {
				id = id + checklist[i].value;
				count++;
			}
		}
		if (count == 1) {
			window.location.href = "yueyogaAdmin/toMemberDetail.jhtml?id=" + id;
		} else {
			alert("请选择一行进行编辑");
		}
	}
	function changePage(value) {
		value = value * 1;
		var totalPages = '${totalPages}';
		if (value > totalPages) {
			value = totalPages;
		} else if (value < 1) {
			value = 1;
		}
		$("#txtPageNumber").val(value);
		goToPage(value);
	}
	function goToPage(pageNo) {
		$("#hidPageNo").val(pageNo);
		var syjq1 = "${syjq}";
		var syts1 = "${syts}";
		var sycs1 = "${sycs}";
		var mglts1 = "${mglts}";
		var mgzts1 = "${mgzts}";
		var syjq = "";
		var syts = "";
		var sycs = "";
		var mglts = "";
		var mgzts = "";
		if(syjq1!=""){
			syjq = syjq1;
		}
		if(syts1!=""){
			syts = syts1;		
		}
		if(sycs1!=""){
			sycs = sycs1;
		}
		if(mglts1!=""){
			mglts = mglts1;
		}
		if(mgzts1!=""){
			mgzts = mgzts1;
		}
		var action = "yueyogaAdmin/searchMember.jhtml?syjq="+syjq+"&syts="+syts+"&sycs="+sycs+"&mglts="+mglts+"&mgzts="+mgzts;
		var oldUrl = $("form[name=taskForm]").attr("action");
		if(syjq!=""||syts!=""||sycs!=""||mglts!=""||mgzts!=""){
			$("form[name=taskForm]").attr("action", action);
			$("form[name=taskForm]").submit();
		}else{
			$("form[name=taskForm]").attr("action", oldUrl);
			$("form[name=taskForm]").submit();
		}
	}
	function slideImpDIV(){
		$("#div_import").slideToggle("fast");
		$("#filePath").val("");
	}
	function uploadXlsx(){
		var val = $("#lefile").val();
		var basePath = $("#basePath").val();
		$("#lefile").val(basePath + val);
	}
	function importMembers(){
		var filePath = $("#lefile").val();
		if(filePath){
			var wjhz = filePath.substring(filePath.lastIndexOf('.')+1,filePath.length);
			if(wjhz=='xls'|| wjhz=='xlsx'){
				document.uploadFile.submit();
				slideImpDIV();
			}else{
				slideImpDIV();
				alert("请上传正确的文件!");
				return;
			}
		}else{
			slideImpDIV();
			alert("请上传模板!");
			return;
		}
	}
	function documentReady(){
		var msg = "${msg}";
		var key = "${key}";
		if(key == "5"){
			var alertInfo = "";
			var total = "${total}";
			var ecount = "${ecount}";
			var fcount = "${fcount}";
			var eInfo = "${cfInfo}";
			var fInfo = "${ffInfo}";
			var eno = "${eno}";
			var fno = "${fno}";
			alertInfo = "导入总条数：" + total +", ";
			alertInfo +="重复数据个数：" + ecount +", ";
			var efs = eInfo.split("!");
			var ffs = fInfo.split("!");
			if(ecount*1 > 0){
				alertInfo += "<br><div class='imp-xy'>卡号&nbsp;&nbsp;&nbsp;</div><div class='imp-xy'>手机号</div><br>";
				for(var i=0;i<efs.length;i++){
					var efss = efs[i].split("--");
					if(efss.length > 0){
						alertInfo +="<div class='imp-xy'>"+efss[0] + "-</div><div class='imp-xy' style='margin-right:10px;'>" + efss[1] +"</div>";
					}
					if(i>0&&i%2!=0){
						alertInfo +="<br>";
					}
				}
			}
			alertInfo +="<br>";
			alertInfo +="失败数据个数：" + fcount +",";
			if(fcount*1 > 0){
				alertInfo += "<br><div class='imp-xy'>卡号&nbsp;--</div><div class='imp-xy'>手机号</div><br>";
				for(var i=0;i<ffs.length;i++){
					var ffss = ffs[i].split("--");
					if(ffss.length > 0){
						alertInfo +="<div class='imp-xy'>"+ffss[0] + "-</div><div class='imp-xy' style='margin-right:10px;'>" + ffss[1] +"</div>";
					}
					if(i>0&&i%2!=0){
						alertInfo +="<br>";
					}
				}
			}
			var scount = total * 1 - (ecount*1 + fcount*1);
			alertInfo += "导入成功数：" + scount + " .";
			var d = alert(alertInfo);
			setTimeout(function(){
				d.close().remove();
				var oldUrl = $("form[name=taskForm]").attr("action");
				$("form[name=taskForm]").attr("action", oldUrl);
				$("form[name=taskForm]").submit();
			},15000);
		}else{
			if(msg){
				var d = alert(msg);
				setTimeout(function(){
					d.close().remove();
				},1000);
			}
		}
}
</script>